package com.example.exception;

/**
 * 授权异常类
 * 用于处理用户授权相关的异常
 */
public class AuthorizationException extends BaseException {
    
    public AuthorizationException(String errorCode, String errorMessage) {
        super(errorCode, errorMessage, ErrorCategory.AUTHORIZATION);
    }
    
    public AuthorizationException(String errorCode, String errorMessage, Object errorDetails) {
        super(errorCode, errorMessage, errorDetails);
        setErrorCategory(ErrorCategory.AUTHORIZATION);
    }
    
    // ========== 权限相关授权异常 ==========
    
    public static AuthorizationException permissionDenied() {
        return new AuthorizationException(ErrorCode.PERMISSION_DENIED, "权限不足");
    }
    
    public static AuthorizationException permissionDenied(String resource) {
        return new AuthorizationException(ErrorCode.PERMISSION_DENIED, "权限不足，无法访问: " + resource);
    }
    
    public static AuthorizationException permissionDenied(String resource, String action) {
        return new AuthorizationException(ErrorCode.PERMISSION_DENIED, 
            String.format("权限不足，无法对 %s 执行 %s 操作", resource, action));
    }
    
    // ========== 角色相关授权异常 ==========
    
    public static AuthorizationException roleRequired() {
        return new AuthorizationException(ErrorCode.PERMISSION_DENIED, "需要特定角色权限");
    }
    
    public static AuthorizationException roleRequired(String roleName) {
        return new AuthorizationException(ErrorCode.PERMISSION_DENIED, "需要角色权限: " + roleName);
    }
    
    // ========== 菜单访问相关授权异常 ==========
    
    public static AuthorizationException menuAccessDenied() {
        return new AuthorizationException(ErrorCode.MENU_ACCESS_DENIED, "菜单访问被拒绝");
    }
    
    public static AuthorizationException menuAccessDenied(String menuName) {
        return new AuthorizationException(ErrorCode.MENU_ACCESS_DENIED, "菜单访问被拒绝: " + menuName);
    }
}
